//VERSION 1.0 - Flown on Mini Bexus 26. Sept 2012 to ~10km alt
// SETTINGS
#define VX_VEHICLE_RELEASE_BOX 25000 // in m, vehicle release box FLIGHT SETTING

int vx_launch_counter = 0;

// Checks if its time to release the UAV from the balloon
void vx_launch_check() {
  //long homebase_dist = vx_calculate_wp_distance(g_gps->latitude, g_gps->longitude, vx_g_home.lat, vx_g_home.lon);
  //long homebase_dist = vx_calculate_wp_distance(vx_g_current_pos.lat, vx_g_current_pos.lon, vx_g_home.lat, vx_g_home.lon);
  long homebase_dist = vx_calculate_wp_distance(vx_g_current_pos.lat, vx_g_current_pos.lon, vx_g_center_circle.lat, vx_g_center_circle.lon);
  
  if(homebase_dist > VX_VEHICLE_RELEASE_BOX) {
    vx_g_launch_servo = true;      
    vx_para_manual_ascent_off();
    

    
    if(vx_launch_counter < 4) {
      vx_teleSendWarning(VX_TELE_WARNING_UAVLAUNCH__AUTO_BOX);
      vx_launch_counter++;
    }
    // DEBUGGING
    //Serial.println("DEBUG: WANT TO LAUNCH UAV FROM BALLOON (100 m)."); 
  }
}

void vx_launch_manual() {
  vx_g_launch_servo = true;
 
  vx_para_manual_ascent_off();
  vx_teleSendWarning(VX_TELE_WARNING_UAVLAUNCH__MANUAL);
  //Serial.println("DEBUG: WANT TO LAUNCH UAV FROM BALLOON (manual)."); 
}

void vx_launch_auto() {
  vx_g_launch_servo = true;
  
  
  vx_para_manual_ascent_off();
  vx_teleSendWarning(VX_TELE_WARNING_UAVLAUNCH__AUTO_DROP);
  //Serial.println("DEBUG: WANT TO LAUNCH UAV FROM BALLOON (auto)."); 
}


